package cn.zn.modules.money.cur.controller;

import cn.zn.framework.common.utils.R;
import cn.zn.framework.common.vo.FinanceValues;
import cn.zn.modules.money.cur.entity.TMoneyInfoDetailAttach;
import cn.zn.modules.money.cur.service.TMoneyInfoDetailAttachService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Arrays;

@RestController
@RequestMapping("money/cur/moneyinfodetailattach")
public class TMoneyInfoDetailAttachController {

    @Autowired
    private TMoneyInfoDetailAttachService tMoneyInfoDetailAttachService;
    @Autowired
    private FinanceValues financeValues;

    @GetMapping("list/{detailId}")
    @ApiOperation("查询列表")
    public R list(@PathVariable String detailId) {
        return R.ok()
                .put("domain", financeValues.getFile().getDomain())
                .put("list", tMoneyInfoDetailAttachService.list(new QueryWrapper<TMoneyInfoDetailAttach>()
                .eq("T_MONEY_INFO_DETAIL_ID_", detailId)
                .orderByDesc("CREATE_TIME_")
        ));
    }

    @PostMapping("upload/{detailId}")
    @ApiOperation("上传附件")
    public R uploadAttach(@PathVariable String detailId, @RequestParam("fileupload") MultipartFile[] fileupload) {
        tMoneyInfoDetailAttachService.saveAttach(detailId, fileupload);
        return R.ok();
    }

    @DeleteMapping
    @ApiOperation("删除附件")
    public R delete(@RequestBody String[] ids) {
        tMoneyInfoDetailAttachService.deleteAttach(Arrays.asList(ids));
        return R.ok();
    }
}
